﻿/*
    Project: IV:MP GUI Editor (http://code.google.com/p/ivmp-gui-editor)
    Code license: GNU Lesser GPL (http://www.gnu.org/copyleft/lesser.html) 
 */

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace IvmpEditor
{
    public abstract class GUIContainer : GUIElement
    {
        // Children collecttion:
        protected List<GUIElement> containerElements;
        public virtual int GetChildrenCount() { return containerElements.Count; }
        public abstract void ChildAdd(GUIElement child);
        public abstract void ChildRemove(GUIElement child);
        public virtual GUIElement ChildGet(int index) { return containerElements[index]; } //TODO make safier
        public virtual GUIElement ChildGetByControl(Control ctrl)
        {
            foreach (GUIElement elem in containerElements)
                if (elem.NativeControl == ctrl)
                    return elem;

            return null;
        }
        public virtual int ChildIdByName(string varName)
        {
            for (int i = 0; i < containerElements.Count; i++)
                if (containerElements[i].GetName() == varName)
                    return i;

            return -1;
        }
        public virtual bool ChildExists(string varName) { return ChildIdByName(varName) != -1; }
        public virtual List<GUIElement> GetChildren() { return containerElements; }

        // Virtual focus:
        protected GUIElement focusedElement;
        public virtual void SetVirtualFocusOn(GUIElement elem)
        {
            focusedElement = elem;
        }
        public virtual GUIElement GetVirtualFocused()
        {
            return focusedElement;
        }
    }
}
